Run a Command Prompt command from Desktop Shortcut

Is it possible to create a desktop shortcut that, when pressed, will open command prompt and run a pre-defined command?

Yes! You can create a shortcut to cmd.exe with a command specified after it. Alternatively you could create a batch script, if your goal is just to have a clickable way to run commands.

Steps:

  1. Right click on some empty space in Explorer, and in the context menu go to "New/Shortcut".

  2. When prompted to enter a location put either:

"C:\Windows\System32\cmd.exe /k Example" This will run the command and keep the command prompt open after.

or

"C:\Windows\System32\cmd.exe /c Example" This will run the command and the close the command prompt.

Swap out "Example" with your desired command.

Notes:

Addition: replace 'Example' by a bat-file. C:/workspace/startup.bat to load a bat file which prepares your command window. Hint: I always add color to the different command-shortcuts that I startup. Easy to see where you are working. Add them in the shortcut properties (right-click).


Yes, make its path:

%comspec% /k DIR C:\

or

%comspec% /k "c:\foo\bar.exe" /1234


Using the DOS “start” command with parameters

I have a Virtual Machine in Virtual PC 2007.

To start it from the desktop, I have the following command in a batch file:

"c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch

But that leaves a dos prompt on the host machine until the virtual machine shuts down, and I exit out of the Virtual PC console. That's annoying.

So I changed my command to use the START command, instead:

start "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc MY-PC -launch

But it chokes on the parameters passed into Virtual PC.



START has a peculiarity involving double quotes around the first parameter. If the first parameter has double quotes it uses that as the optional TITLE for the new window.

I believe what you want is:

start "" "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc MY-PC -launch

In other words, give it an empty title before the name of the program to fake it out.



Instead of a batch file, you can create a shortcut on the desktop.

Set the target to:

"c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch

and you're all set. Since you're not starting up a command prompt to launch it, there will be no DOS Box.



The spaces are DOSs/CMDs Problems so you should go to the Path via:

cd "c:\program files\Microsoft Virtual PC"

and then simply start VPC via:

start Virtual~1.exe -pc MY-PC -launch

~1 means the first exe with "Virtual" at the beginning. So if there is a "Virtual PC.exe" and a "Virtual PC1.exe" the first would be the Virtual~1.exe and the second Virtual~2.exe and so on.

Or use a VNC-Client like VirtualBox.



You can use quotes by using the [/D"Path"] use /D only for specifying the path and not the path+program. It appears that all code on the same line that follows goes back to normal meaning you don't need to separate path and file.

start  /D "C:\Program Files\Internet Explorer\" IEXPLORE.EXE

:: or

start  /D "TITLE" "C:\Program Files\Internet Explorer\" IEXPLORE.EXE

:: will start IE with default web page.

start /D "TITLE" "C:\Program Files\Internet Explorer\" IEXPLORE.EXE www.bing.com :: Starts with Bing, but does not reset your home page.

:: /D stands for "directory" and using quotes is OK!

:: WRONG start /D "TITLE" "C:\Program Files\Internet Explorer\IEXPLORE.EXE" :: ERROR "The current directory is invalid." /D must only be followed by a directory path.
:: Then space and the batchfile or program you wish to start/run"

Tested and works under XP but windows Vista/7/8 may need some adjustments to UAC.

"/b" parameter

start /b "" "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch



If you want passing parameter and your .exe file in test folder of c: drive

start "parameter" "C:\test\test1.exe" -pc My Name-PC -launch

If you won't want passing parameter and your .exe file in test folder of c: drive

start "" "C:\test\test1.exe" -pc My Name-PC -launch

If you won't want passing parameter and your .exe file in test folder of H: (Any Other)drive

start "" "H:\test\test1.exe" -pc My Name-PC -launch